package com.resource.gsLoader
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.DataLoader;
	import com.greensock.loading.XMLLoader;
	
	import flash.utils.Dictionary;

	/**
	 * 数据加载类(xml,txt...)
	 * */
	public class MyDataLoader extends LoaderBase
	{
		private static var _instance:MyDataLoader;
		
		private var _load:Dictionary = new Dictionary();
		public function MyDataLoader()
		{
			super();
			if (!_instance) 
			{
				_instance = this;
			}else
				throw new Error("mydataloader is single");
		}
		
		
		public static function getInstance():MyDataLoader
		{
			if(!_instance)
				_instance = new MyDataLoader();
			return _instance;		
		}
		
		
		override public function loadMultiple(arr:Array):void
		{
			var num:int = 0;
			while(arr[num])
			{
				var dl:DataLoader = new DataLoader(arr[num][0],{onComplete:onComplete,autoDispose:true,format:"text"});
				_callBackDic[dl] = arr[num][1];
				_loader.append(dl);
				num++;
			}
			_loader.load();
			
		}
	
		
		override public function load(url:String,fun:Function):void
		{
			var dl:DataLoader = new DataLoader(url,{autoDispose:true,format:"text",onComplete:onComplete});
			_callBackDic[dl] = fun;
			dl.load();
		}
		
		
		private function onComplete(e:LoaderEvent):void
		{
			if(_callBackDic[e.target] != null)
				_callBackDic[e.target](e.target.content);
			delete _callBackDic[e.target];
		}
		
		
	
	}
}